<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.util.List"%>
<%@ page import="org.dualr.litelog.entity.Post"%>
<%@ page import="org.dualr.litelog.entity.Link"%>
<%@ page import="org.dualr.litelog.entity.Tag"%>
<%@ page import="org.dualr.litelog.entity.Comment"%>
<%@ page import="org.dualr.litelog.entity.Category"%>
<%@ page import="org.dualr.litelog.dao.CategoryDao"%>
<%@ page import="org.dualr.litelog.dao.PostDao"%>
<%@ page import="org.dualr.litelog.utils.LiteLogUtil"%>
<%@ page import="com.google.appengine.api.users.UserService"%>
<%@ page import="com.google.appengine.api.users.UserServiceFactory"%>
<%@ page import="com.google.appengine.api.users.User"%>
<%
	String url = "";
	String title = "";
	String description = "";
	String admin = "";
	url = LiteLogUtil.getInstance().getPropsValue("/litelog.properties", "litelog.url");
	title = LiteLogUtil.getInstance().getPropsValue("/litelog.properties", "litelog.title");
	description = LiteLogUtil.getInstance().getPropsValue("/litelog.properties", "litelog.description");
	admin = LiteLogUtil.getInstance().getPropsValue("/litelog.properties", "litelog.author");
%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%
	String author = "";
	String mail = "";
	UserService userService = UserServiceFactory.getUserService();
	if (request.getUserPrincipal() != null) {
		User user = userService.getCurrentUser();
		author = user.getNickname();
		mail = user.getEmail();
	}
	

	Post post = (Post)request.getAttribute("Post");
	if (post == null){
		%>
			<jsp:forward page="404.html"></jsp:forward>
		<%
	}
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="google-site-verification" content="std42EJzAI2L64CE1x9FGlnYV169PQstLfrRgDdoWe4" />
<meta name="alexaVerifyID" content="oj-0I9yaFc0T9s1Z3wbhc7Vhjug" />
<title><%=post.getTitle()%></title>
<link href="http://mimaiji.appspot.com/rss" title="DualR's weBlog RSS Feed" type="application/rss+xml" rel="alternate"/>
<link href="favicon.ico" type="image/x-icon" rel="shortcut icon" />
<link href="simplestyle.css" rel="stylesheet" type="text/css" media="screen"/>
<link href="view.css" rel="stylesheet" type="text/css" media="screen"/>
<script type="text/javaScript" src="js/common.js"></script>
</head>
<body>
<div id="wrapper">
	<div id="header">
		<div id="logo"><h1><a href="http://www.mimaiji.com" title="DualR's weblog">DualR's WeBlog</a></h1></div>
		<div id="nav">
			<ul>
					<li><a href="./" class="active" title="<%=title%>">首页</a></li>
					<li><a href="about.html" title="about">关于</a></li>
					<li><a href="./rss" title="feed">RSS</a></li>
			</ul>
			<!--<span><input type="text" name="searchword" id="search-word"/><input type="submit" value="Go" id="search-button"/></span>-->
		</div>
	</div>
	<div id="main">
		<div id="content">
			<div class="post">
				<h2><a href="post?method=view&id=<%=post.getId()%>" title="阅读全文"><%=post.getTitle()%></a></h2>
				<p class="meta">
					<a href="<%=url%>"><%=admin%></a> Post at <%=LiteLogUtil.getInstance().formateDate(post.getPostDate(), "yyyy/MM/dd/ a")%> | <a href="article?method=category&param=<%=post.getCategoryId()%>" title="category"><%=CategoryDao.getInstance().getNameById(post.getCategoryId())%></a> | <a href="article?method=tag&param=<%=post.getTag()%>" title="tag"><%=post.getTag()%></a>
					| <a href="post?method=view&id=<%=post.getId()%>"><%=post.getHits()%> views</a> | <a href="post?method=view&id=<%=post.getId()%>#comment_form"><%=post.getCommentCount()%> comments</a>
				</p>
				<div class="entry">
					<%=post.getContent().getValue()%>
				</div>
			</div>
		<!--关闭评论-->
			<%
				if(post.getCommentStatus().equals("close")){
			%>
				<h2 class="comment_tip">评论已关闭</h2>
			<%
				}
			%>
		<!--关闭评论-->
		
		<!--开放评论-->			
			<%
				if(post.getCommentStatus().equals("open")){
					List<Comment> commentList = (List<Comment>) request.getAttribute("CommentList");
			%>
						<h2 class="comment_tip"><%=commentList.size()%>Responses
						
							<a href="#comment_form">Leave Your comment</a>
						
						</h2>
			<%
						if(commentList != null){
							int i=1;
							for(Comment comment : commentList){
			%>
								<div class="comment" id="comment-<%=comment.getId()%>">
									<div class="gravatar">
										<a href="<%=comment.getWebsite()%>" name="comment-<%=comment.getId()%>" target="_blank"><img src="http://www.gravatar.com/avatar/<%=LiteLogUtil.getInstance().getMD5Str(comment.getMail())%>?s=48"></img></a>
									</div>
									<div class="comment_content">
									<div class="comment_meta">
										<p><label class="sequence"><%=i++%></label> <%=comment.getAuthor()%></p>
										<p>post at <%=LiteLogUtil.getInstance().formateDate(comment.getCommentDate(), "yyyy/MM/dd")%><a id="reply_<%=comment.getId()%>" href="javascript:reply('<%=comment.getId()%>','<%=comment.getAuthor()%>')"> 回复</a></p>
									</div>
									<div id="comment<%=comment.getId()%>" class="comment_entry">
									<%=comment.getContent().getValue()%>
									</div>
									</div>
									<div class="clear"></div>
								</div>
			<%
							}
						}
					
			%>
					<div id="postComment">
						<h2 class="comment_tip">Leave Your Reply</h2>
						<form action="comment?postId=<%=post.getId()%>" method="post" id="comment_form" name="comment_form">
							<input type="hidden" value="0" name="replyId" id="replyId"/>
							<p class="commentContent"><input type="text" name="author" id="author" value="<%=author%>"></input><span class="star"> * </span>Name</p>
							<p class="commentContent"><input type="text" name="mail" id="mail" value="<%=mail%>"></input><span class="star"> * </span>Mail (will not be published)</p>
							<p class="commentContent"><input type="text" name="website" id="website"></input><span style="color:#FFFFFF;font-size:14px; font-weight: bold;"> * </span>   WebSite</p>
							<p class="commentContent"><textarea name="content" id="commentContent" rows="4" cols="100"></textarea></p>
							<p class="commentContent"><input type="text" name="code" id="code"/><span class="star"> * </span><b><%=request.getAttribute("num1")%> + <%=request.getAttribute("num2")%> = ?</b></p>
							<p class="commentContent">
							<select name="replyMailMark">
								<option value="yes" selected="selected">Yes</option>
								<option value="no">No</option>
							</select>
							<span style="color:#FFFFFF;font-size:14px; font-weight: bold;"> * </span>Send a email to me when anyone post new reply
							</p>
							<p class="commentContent"><input type="button" id="submit_button" value="Submit" onclick="postComment()"></input></p>
						</form>
					</div>
			<%
				}
			%>	
		<!--开放评论-->	
		
		<!--google用户评登陆评论-->
			<%
				if(post.getCommentStatus().equals("registered_only")){
					List<Comment> commentList = (List<Comment>) request.getAttribute("CommentList");
			%>
						<h2 class="comment_tip"><%=commentList.size()%>Responses
			<%
							if(author == null || "".equals(author)){
								String thisURL = basePath + "post?method=view&id="+post.getId();
			%>
							<a href="<%=userService.createLoginURL(thisURL)%>">限googel account登陆评论!</a>
			<%
						}else{
			%>
						<a href="#comment_form">Leave Your comment</a>
			<%
						}
			%>	
						</h2>
			<%
						if(commentList != null){
							int i=1;
							for(Comment comment : commentList){
			%>
								<div class="comment" id="comment-<%=comment.getId()%>">
									<div class="gravatar">
										<a href="<%=comment.getWebsite()%>" name="comment-<%=comment.getId()%>" target="_blank"><img src="http://www.gravatar.com/avatar/<%=LiteLogUtil.getInstance().getMD5Str(comment.getMail())%>?s=48"></img></a>
									</div>
									<div class="comment_content">
									<div class="comment_meta">
										<p><label class="sequence"><%=i++%></label> <%=comment.getAuthor()%></p>
										<p>post at <%=LiteLogUtil.getInstance().formateDate(comment.getCommentDate(), "yyyy/MM/dd")%><a id="reply_<%=comment.getId()%>" href="javascript:reply('<%=comment.getId()%>','<%=comment.getAuthor()%>')"> 回复</a></p>
									</div>
									<div id="comment<%=comment.getId()%>" class="comment_entry">
									<%=comment.getContent().getValue()%>
									</div>
									</div>
									<div class="clear"></div>
								</div>
			<%
							}
						}
					
			%>
			
			<%
					if(author != null && !"".equals(author)){
			%>
				<div id="postComment">
						<h2 class="comment_tip">Leave Your Reply</h2>
						<form action="comment?postId=<%=post.getId()%>" method="post" id="comment_form" name="comment_form">
							<input type="hidden" value="0" name="replyId" id="replyId"/>
							<p class="commentContent"><input type="text" name="author" id="author" value="<%=author%>"></input><span class="star"> * </span>Name</p>
							<p class="commentContent"><input type="text" name="mail" id="mail" value="<%=mail%>"></input><span class="star"> * </span>Mail (will not be published)</p>
							<p class="commentContent"><input type="text" name="website" id="website"></input><span style="color:#FFFFFF;font-size:14px; font-weight: bold;"> * </span>   WebSite</p>
							<p class="commentContent"><textarea name="content" id="commentContent" rows="4" cols="100"></textarea></p>
							<p class="commentContent"><input type="text" name="code" id="code"/><span class="star"> * </span><b><%=request.getAttribute("num1")%> + <%=request.getAttribute("num2")%> = ?</b></p>
							<p class="commentContent">
							<select name="replyMailMark">
								<option value="yes" selected="selected">Yes</option>
								<option value="no">No</option>
							</select>
							<span style="color:#FFFFFF;font-size:14px; font-weight: bold;"> * </span>Send a email to me when anyone post new reply
							</p>
							<p class="commentContent"><input type="button" id="submit_button" value="Submit" onclick="postComment()"></input></p>
						</form>
					</div>
			<%
					}
			%>
			<%
				}
			%>	
		<!--登陆用户评论-->			
				
		</div>
		<div id="main-right">
		<div class="right-column">
					<h2 title="Categories">「日志分类」
					</h2>
					<ul>
						<%
							List<Category> categoryList = (List<Category>)request.getAttribute("categoryList");
							if (categoryList != null){
								for(Category category : categoryList){
						%>
						<li><img src="images/dot.gif" alt="dot" /><a href="post?method=category&param=<%=category.getId()%>"><%=category.getName()%></a></li>
						<%
								}
							}
						%>
					</ul>
				</div>
				<div class="right-column">
					<h2 title="Categories">「标签TAG」</h2>
					<ul id="tag">
						<%
							List<Tag> tagList = (List<Tag>)request.getAttribute("tagList");
							if (tagList != null){
								for(Tag tag : tagList){
									%>
										<a href="post?method=tag&param=<%=tag.getTag()%>"><%=tag.getTag()%>[<%=tag.getCount()%>]</a>
									<%
								}
							}
						%>
						
					</ul>
				</div>
				<div class="right-column">
					<h2>「热门日志」</h2>
					<ul>
					<%
						List<Post> popPostList = (List<Post>)request.getAttribute("PopPostList");
						if (popPostList != null){
							for(Post popPost : popPostList){
					%>
					<li><img src="images/dot.gif" alt="dot" /><a href="post?method=view&id=<%=popPost.getId()%>" title="<%=popPost.getTitle()%>"><%=popPost.getTitle()%></a></li>
					<%
							}
						}
					%>
					</ul>
				</div>
				<div class="right-column">
					<h2>「最新日志」</h2>
					<ul>
					<%
						List<Post> lastPostList = (List<Post>)request.getAttribute("LastPostList");
						if (lastPostList != null){
							for(Post lastPost : lastPostList){
					%>
					<li><img src="images/dot.gif" alt="dot" /><a href="post?method=view&id=<%=lastPost.getId()%>" title="<%=lastPost.getTitle()%>"><%=lastPost.getTitle()%></a></li>
					<%
							}
						}
					%>
					</ul>
				</div>
		</div>
		<div class="clear"></div>
	</div>
	<%@include file="index_footer.jsp" %>
</div>
</body>
</html>
